﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.MT3DMS.DomainLayer;

namespace HA.ModFlow.Controls.MT3DMSWindows
{
    /// <summary>
    /// winAdvection.xaml 的交互逻辑
    /// </summary>
    public partial class winAdvection : Window
    {
        public winAdvection(MT3DMSData mtData)
        {
            InitializeComponent();
            this._Adv = (Advection)mtData.Advection.Clone();
            _mdOption = mtData.BasicTransport.ModelOption;
        }
        MTModelOption _mdOption;
        private Advection _Adv;

        public Advection Adv
        {
            get { return _Adv; }
            set { _Adv = value; }
        }

        private void btnParticles_Click(object sender, RoutedEventArgs e)
        {
            winParticles winpart = new winParticles(this.Adv,this._mdOption);
            winpart.Owner = this;
            winpart.ResizeMode = ResizeMode.NoResize;
            winpart.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            if (winpart.ShowDialog().Value)
            {
                this.Adv = winpart.Adv;
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = this.Adv;
            switch (this.Adv.SolutionScheme)
            {
                case AdvectionSolutionScheme.ThirdOrderTVD:
                    this.cboSolution.SelectedIndex = 0;
                    break;
                case AdvectionSolutionScheme.StandardFiniteDifference:
                    this.cboSolution.SelectedIndex = 1;
                    break;
                case AdvectionSolutionScheme.MethodOfCharacteristics:
                    this.cboSolution.SelectedIndex = 2;
                    break;
                case AdvectionSolutionScheme.ModifiedMethodOfCharacteristics:
                    this.cboSolution.SelectedIndex = 3;
                    break;
                case AdvectionSolutionScheme.HbridMOCOrMMOC:
                    this.cboSolution.SelectedIndex = 4;
                    break;
            }

            if (this.Adv.WeightingScheme == AdvecionWeightingScheme.UpstreamWeighting)
            {
                this.chkUpstream.IsChecked = true;
            }
            else
            {
                this.chkCentral.IsChecked = true;
            }

            if (this.Adv.TrackingAlgorithm == AdvectionTrackingAlgorithm.FirstOrderEuler)
            {
                this.chkFirst.IsChecked = true;
            }
            else if (this.Adv.TrackingAlgorithm == AdvectionTrackingAlgorithm.FourthOrderRungeKutta)
            {
                this.chkFourth.IsChecked = true;
            }
            else
            {
                this.chkRunge.IsChecked = true;
            }
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            if (this.chkUpstream.IsChecked .Value )
            {
                this.Adv.WeightingScheme = AdvecionWeightingScheme.UpstreamWeighting;
            }
            else
            {
                this.Adv.WeightingScheme = AdvecionWeightingScheme.CentralInSpaceWeighting;
            }

            if (this.chkFirst.IsChecked.Value )              
            {
                this.Adv.TrackingAlgorithm = AdvectionTrackingAlgorithm.FirstOrderEuler;
             
            }
            else if (this.chkFourth.IsChecked .Value)
            {
                this.Adv.TrackingAlgorithm = AdvectionTrackingAlgorithm.FourthOrderRungeKutta;             
            }
            else
            {
                this.Adv.TrackingAlgorithm = AdvectionTrackingAlgorithm.RungeKuttaAtOrNearSource;   
            }


            this.DialogResult = true;
            this.Close();
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void cboSolution_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch (this.cboSolution.SelectedIndex)
            {
                case 0:
                    this.Adv.SolutionScheme = AdvectionSolutionScheme.ThirdOrderTVD;
                    this.chkUpstream.IsEnabled = false;
                    this.chkCentral.IsEnabled = false;
                    this.chkFirst.IsEnabled = false;
                    this.chkFourth.IsEnabled = false;
                    this.chkRunge.IsEnabled = false;
                    this.txtWD.IsEnabled = false;
                    break;
                case 1:
                    this.Adv.SolutionScheme = AdvectionSolutionScheme.StandardFiniteDifference;
                    this.chkUpstream.IsEnabled = true;
                    this.chkCentral.IsEnabled = true;
                    this.chkFirst.IsEnabled = false;
                    this.chkFourth.IsEnabled = false;
                    this.chkRunge.IsEnabled = false;
                    this.txtWD.IsEnabled = false;
                    break;
                case 2:
                    this.Adv.SolutionScheme = AdvectionSolutionScheme.MethodOfCharacteristics;
                    this.chkUpstream.IsEnabled = false;
                    this.chkCentral.IsEnabled = false;
                    this.chkFirst.IsEnabled = true;
                    this.chkFourth.IsEnabled = true;
                    this.chkRunge.IsEnabled = true;
                    this.txtWD.IsEnabled = true;
                    break;
                case 3:
                    this.Adv.SolutionScheme = AdvectionSolutionScheme.ModifiedMethodOfCharacteristics;
                    this.chkUpstream.IsEnabled = false;
                    this.chkCentral.IsEnabled = false;
                    this.chkFirst.IsEnabled = true;
                    this.chkFourth.IsEnabled = true;
                    this.chkRunge.IsEnabled = true;
                    this.txtWD.IsEnabled = true;
                    break;
                case 4:
                    this.Adv.SolutionScheme = AdvectionSolutionScheme.HbridMOCOrMMOC;
                    this.chkUpstream.IsEnabled = false;
                    this.chkCentral.IsEnabled = false;
                    this.chkFirst.IsEnabled = true;
                    this.chkFourth.IsEnabled = true;
                    this.chkRunge.IsEnabled = true;
                    this.txtWD.IsEnabled = true;
                    break;
            }

        }
    }
}
